package com.lxh.student.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxh.student.common.ResponseResult;
import com.lxh.student.dao.RcCourseMapper;
import com.lxh.student.entity.RcStudent;
import com.lxh.student.dao.RcStudentMapper;
import com.lxh.student.service.RcStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxh.student.vo.input.SearchChoseCourseVo;
import com.lxh.student.vo.output.ChoseCourseInfoVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LXh
 * @since 2022-10-24
 */
@Service
public class RcStudentServiceImpl extends ServiceImpl<RcStudentMapper, RcStudent> implements RcStudentService {

    @Autowired
    private RcStudentMapper studentMapper;
    @Autowired
    private RcCourseMapper courseMapper;
    @Override
    public ResponseResult searchCourse(SearchChoseCourseVo courseVo) {
        PageHelper.startPage(courseVo.getIndex(), 8);
        List<ChoseCourseInfoVo> list = courseMapper.searchCourse(courseVo);
        PageInfo<ChoseCourseInfoVo> info= new PageInfo<>(list);

        // 查询 年级
        // 查询 院系id
        // 查询 列表 用户已选择的课程id list


        return ResponseResult.createSuccess(info);
    }

    @Override
    public ResponseResult getStudentInfo(Integer userId) {
        return ResponseResult.createSuccess(studentMapper.getStudentInfo(userId));
    }

    @Override
    public ResponseResult updateStudent(RcStudent stu) {
        RcStudent rcStudent = studentMapper.selectById(stu.getStudentId());
        if (rcStudent == null) {
            return ResponseResult.createFail("该学员不存在,请重新再试,或者联系管理员");
        }
        if (rcStudent.getStudentBirthday()!=null&&stu.getStudentBirthday().getTime()>System.currentTimeMillis()) {
            return ResponseResult.createFail("该学员要先出生了再说");
        }
        // 复制 stu的数据给 rcStudent   复制不复制都无所谓  直接给updateById传入stu
//        BeanUtils.copyProperties(stu, rcStudent);
        System.out.println("这是什么！！！！！！！！！！！！！！！！！！！！！！！！！！！！"+rcStudent);
        System.out.println("那是什么？？？？？？？？？？？？？？？？？？？？？？？？？？？"+stu);
        if (studentMapper.updateById(stu)>0) {
            return ResponseResult.createSuccess("修改成功");
        }
        return ResponseResult.createFail("修改失败");
    }
}
